package org.niu.backtracking;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Permutation {
    ArrayList<String> ans;
    void backtracking(String str,StringBuilder s){
        if(s.length() == str.length()){
            if(!ans.contains(s)){
                ans.add(s.toString());
            }
            return;
        }
        for(int i = 0;i < str.length();i++){
            s.append(str.charAt(i));
            backtracking(str,s);
            s.deleteCharAt(s.length()-1);
        }
    }
    public ArrayList<String> Permutation(String str) {
        ans = new ArrayList<>();
        StringBuilder s = new StringBuilder();
        backtracking(str, s);
        return ans;
    }
}
